Skip to content

Fix/stream contract dead code cleanup#593

Open
devfoma wants to merge 2 commits into
LabsCrypt:mainfrom
devfoma:fix/stream-contract-dead-code-cleanup
Open

Fix/stream contract dead code cleanup#593
devfoma wants to merge 2 commits into
LabsCrypt:mainfrom
devfoma:fix/stream-contract-dead-code-cleanup

Conversation

@devfoma
Copy link
Copy Markdown

@devfoma devfoma commented May 30, 2026

Pure dead-code cleanup in contracts/stream_contract. Two self-contained fixes, one commit each. No logic changes, no test changes.


Fix 1 — Remove duplicate if stream.paused guard in withdraw

Fixes #534

The withdraw function had two back-to-back identical guards:

// Before
Self::validate_stream_active(&stream)?;
if stream.paused {
    return Err(StreamError::StreamInactive);
}
if stream.paused {          // ← dead code, never reached
    return Err(StreamError::StreamInactive);
}

Because the first if stream.paused block always returns early when true, the second block was unreachable. It was removed, leaving the single correct check in place.

Impact: No behaviour change. Reduces compiled WASM size by 3 lines of redundant bytecode. Eliminates reader confusion.


Fix 2 — Delete orphaned contracts/stream_contract/src/stream_contract/ subtree

Deleted: contracts/stream_contract/src/stream_contract/src/test.rs (61 lines)

Fixes #535

A nested stream_contract/src/ directory existed inside the real src/. lib.rs declares mod test;, which Rust resolves to src/test.rs (the 2 349-line real suite) — the nested path is never on the module search path and was therefore never compiled or run.

The 61-line file contained a single fuzz_stream_invariants test exercising four arithmetic invariants. All four are already covered by dedicated tests in the real src/test.rs:

Orphaned invariant Covered by
withdrawn <= deposited test_fuzz_withdrawn_never_exceeds_deposited
claimable <= remaining test_fuzz_claimable_never_exceeds_remaining
rate * elapsed >= 0 test_fuzz_claimable_overflow_and_cancel_invariants
cancel_refund + withdrawn <= deposited test_fuzz_cancel_early_refunds

Impact: No test coverage lost. Removes confusing dead directory from code navigation and search results.


Checklist

  • Dead duplicate if stream.paused block removed from withdraw
  • Orphaned contracts/stream_contract/src/stream_contract/ directory deleted
  • No logic or semantic changes made
  • cargo test scope unaffected (only dead code removed)
  • Each fix is an isolated, atomic commit

devfoma added 2 commits May 29, 2026 20:53
The withdraw function contained an unreachable second if stream.paused
guard immediately after an identical first check. Since validate_stream_active
and the first paused guard already cause an early return, the second block
was dead code. Remove it to improve readability and reduce WASM size.
…irectory

Remove the stale contracts/stream_contract/src/stream_contract/ subtree.
This nested directory was never wired into the crate module tree (lib.rs
declares mod test; which resolves to src/test.rs, not this path), so the
61-line fuzz_stream_invariants stub it contained was never compiled or run.

The four arithmetic invariants it tested (withdrawn<=deposited, claimable<=
remaining, non-negative accrual, cancel_refund+withdrawn<=deposited) are
already covered by test_fuzz_withdrawn_never_exceeds_deposited,
test_fuzz_claimable_never_exceeds_remaining, test_fuzz_cancel_early_refunds,
and test_fuzz_claimable_overflow_and_cancel_invariants in src/test.rs.
@ogazboiz
Copy link
Copy Markdown
Contributor

ogazboiz commented Jun 1, 2026

hey, #706 just merged and fixes a broken test-mock pattern that was causing 'Failed Suites' / 'is not a function' / '0 tests' on backend integration tests. please rebase to pick it up:

git fetch upstream
git rebase upstream/main
git push --force-with-lease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contracts] Remove stray nested src/stream_contract/src/test.rs duplicate [Contracts] Remove duplicate if stream.paused guard in withdraw()

2 participants